package com.caul.demo.hadoop.mapreduce.attention;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by sdliang on 2018/4/8.
 */
public class SecondAttentionReducer extends Reducer<Text, Text, Text, Text> {

  private StringBuilder sb;
  private Text textValue;

  @Override
  protected void setup(Context context) throws IOException, InterruptedException {
    sb = new StringBuilder();
    textValue = new Text();
  }

  @Override
  protected void reduce(Text key, Iterable<Text> values, Context context)
      throws IOException, InterruptedException {
    sb.delete(0, sb.length());
    for (Text value : values) {
      sb.append(",").append(value.toString());
    }
    textValue.set(sb.substring(1));
    context.write(key, textValue);
  }
}
